﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using ArtsShop.DataLayer.DataAccess;

namespace ArtsShop.BusinessLogic
{
    
        public struct ShoppingCartUpdates
        {
            public int ProductId;
            public int PurchaseQantity;
            public bool RemoveItem;
        }

        public partial class ShoppingCart
        {
            public const string CartId = "CartID";

            //------------------------------------------------------------------------------------------------------------------------------------------+
            public String GetShoppingCartId()
            {
                if (HttpContext.Current.Session[CartId] == null)
                {
                    HttpContext.Current.Session[CartId] = System.Web.HttpContext.Current.Request.IsAuthenticated ? "1" : Guid.NewGuid().ToString();
                }
                return HttpContext.Current.Session[CartId].ToString();
            }

            public void AddItem(string cartID, int productID, int quantity)
            {
                ShoppingCartDAO sc = new ShoppingCartDAO();
               try
               {
                 sc.addItemToCart(cartID,productID,quantity);
               }
               catch (Exception exp)
               {
                    throw new Exception("ERROR: Unable to Add Item to Cart - " + exp.Message.ToString(), exp);
                }
            }



            /*
            public decimal getTotal(string cartId)
            {
                
                return sc.getCartTotal(cartId);
            }*/

            public System.Data.DataSet getProducts(string cartId)
            {
                ShoppingCartDAO sc = new ShoppingCartDAO();
                return sc.getCartProducts(cartId);
            }
        }
    
}
